home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / dodge.swf / scripts / __Packages / Missile.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  3.8 KB  |  155 lines

  1. class Missile extends MovieClipHolder implements Steppable
  2. {
  3.    var mc;
  4.    var newAngle;
  5.    var tm;
  6.    var dm;
  7.    static var MAX_SPEED = 6;
  8.    static var ACCEL = 2;
  9.    static var DAMAGE = 1;
  10.    static var GRACE_TIMER = 12;
  11.    static var MISSILE_TIMER = 150;
  12.    static var missiles = new ObjectList();
  13.    var xspeed = 0;
  14.    var yspeed = 0;
  15.    var graceTimer = 0;
  16.    var skipSwitch = true;
  17.    function Missile(x, y, newAngle)
  18.    {
  19.       super(_root.attachMovie("missile1","missile1" + _root.getNextHighestDepth(),_root.getNextHighestDepth()));
  20.       this.mc._x = x;
  21.       this.mc._y = y;
  22.       this.newAngle = newAngle;
  23.       this.createTrailManager();
  24.       this.createDebrisManager();
  25.       this.createSound();
  26.       Missile.add(this);
  27.       Stepper.add(this);
  28.    }
  29.    function getMaxSpeed()
  30.    {
  31.       return Missile.MAX_SPEED;
  32.    }
  33.    function getAccel()
  34.    {
  35.       return Missile.ACCEL;
  36.    }
  37.    function getMissileTimer()
  38.    {
  39.       return Missile.MISSILE_TIMER;
  40.    }
  41.    function getGraceTimer()
  42.    {
  43.       return Missile.GRACE_TIMER;
  44.    }
  45.    static function add(m)
  46.    {
  47.       Missile.missiles.add(m);
  48.    }
  49.    static function remove(m)
  50.    {
  51.       Missile.missiles.remove(m);
  52.    }
  53.    function step()
  54.    {
  55.       this.followPlayer();
  56.       if(this.graceTimer > this.getMissileTimer())
  57.       {
  58.          this.die();
  59.       }
  60.       this.graceTimer = this.graceTimer + 1;
  61.       if(this.mc._x < 0 || this.mc._x > Stage.width || this.mc._y < 0 || this.mc._y > Stage.height)
  62.       {
  63.          this.outOfBounds();
  64.       }
  65.    }
  66.    function createSound()
  67.    {
  68.       SoundManager.fireRedMissile();
  69.    }
  70.    function outOfBounds()
  71.    {
  72.       this.die();
  73.    }
  74.    function createTrailManager()
  75.    {
  76.       this.tm = new EfficientTrailManager(this.mc,this.mc.exhaust1,2,_root.effects < 3 ? null : 16711680,this.getTrailLength(),true,50);
  77.    }
  78.    function getTrailLength()
  79.    {
  80.       if(_root.effects <= 1)
  81.       {
  82.          return 6;
  83.       }
  84.       return 9;
  85.    }
  86.    function createDebrisManager()
  87.    {
  88.       if(_root.effects >= 2)
  89.       {
  90.          this.dm = new DebrisManager(16711680,1);
  91.       }
  92.    }
  93.    function followPlayer()
  94.    {
  95.       if(this.skipSwitch)
  96.       {
  97.          var _loc3_ = undefined;
  98.          if(this.isGrace() && this.newAngle)
  99.          {
  100.             _loc3_ = CustomMath.degToRad(this.newAngle);
  101.          }
  102.          else
  103.          {
  104.             _loc3_ = Math.atan2(_root.player.getMovie()._y - this.mc._y,_root.player.getMovie()._x - this.mc._x);
  105.          }
  106.          var _loc4_ = this.xspeed * this.xspeed + this.yspeed * this.yspeed;
  107.          var _loc5_ = this.getMaxSpeed() * this.getMaxSpeed();
  108.          this.xspeed += this.getAccel() * Math.cos(_loc3_);
  109.          this.yspeed += this.getAccel() * Math.sin(_loc3_);
  110.          if(_loc4_ > _loc5_)
  111.          {
  112.             this.xspeed *= _loc5_ / _loc4_;
  113.             this.yspeed *= _loc5_ / _loc4_;
  114.          }
  115.       }
  116.       this.mc._x += this.xspeed;
  117.       this.mc._y += this.yspeed;
  118.       this.tm.makeTrail();
  119.       this.skipSwitch = !this.skipSwitch;
  120.    }
  121.    function isGrace()
  122.    {
  123.       return this.graceTimer < this.getGraceTimer();
  124.    }
  125.    function getX()
  126.    {
  127.       return this.mc._x;
  128.    }
  129.    function getY()
  130.    {
  131.       return this.mc._y;
  132.    }
  133.    function getDamage()
  134.    {
  135.       return Missile.DAMAGE;
  136.    }
  137.    function hit(m, shapeFlag, isPlayer)
  138.    {
  139.       if(isPlayer || !this.isGrace())
  140.       {
  141.          return m.hitTest(this.mc._x,this.mc._y,shapeFlag);
  142.       }
  143.       return false;
  144.    }
  145.    function die()
  146.    {
  147.       this.dm.createDebrisField(this.mc._x,this.mc._y);
  148.       Stepper.remove(this);
  149.       Missile.remove(this);
  150.       this.tm.die();
  151.       new Explosion(this.mc._x,this.mc._y,1,0);
  152.       this.mc.removeMovieClip();
  153.    }
  154. }
  155.